//
//  DKAlertHelper.m
//  DanKU
//
//  Created by 吴斌 on 2023/10/1.
//

#import "DKAlertHelper.h"
#import "DKMsgPopUp.h"
@interface DKAlertHelper()
@property (nonatomic,strong) DKMsgPopUp *popUp;
@end
@implementation DKAlertHelper
+ (instancetype)sharedInstance{
    static id sharedSingleton = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedSingleton = [[self alloc] init];
    });
    return sharedSingleton;
}
+(void)showMessage:(NSString *)alertMsg{
    if (alertMsg.length <= 0) {
        return;
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [self showPopupMessage:alertMsg toView:nil centerPoint:[UIApplication sharedApplication].delegate.window.center];
    });
}
+ (void)showPopupMessage:(NSString *)message toView:(UIView *)view centerPoint:(CGPoint)point {
    if (view == nil) {
        view = [UIApplication sharedApplication].delegate.window;
    }
    DKAlertHelper *dk_AlertHelper = [DKAlertHelper sharedInstance];
    if (dk_AlertHelper.popUp) {
        [dk_AlertHelper.popUp removeFromSuperview];
        dk_AlertHelper.popUp = nil;
    }
    dk_AlertHelper.popUp = [DKMsgPopUp popupWithText:message];
    [dk_AlertHelper.popUp showInView:view centerAtPoint:point duration:DKPopupDefaultWaitDuration completion:nil];
}
@end
